import request from "@/utils/request";

export default {
  getWarehouseList(searchModel) {
    return request({
      url: "/warehouse/list",
      method: "get",
      params: {
        warehouseName: searchModel.warehouseName,
        pageNo: searchModel.pageNo,
        pageSize: searchModel.pageSize,
      },
    });
  },

  addWarehouse(warehouse) {
    return request({
      url: "/warehouse",
      method: "post",
      data: warehouse,
    });
  },

  getWarehouseById(id) {
    return request({
      url: `/warehouse/${id}`,
      method: "get",
    });
  },

  saveWarehouse(warehouse) {
    if (warehouse.id == null && warehouse.id == undefined) {
      return this.addWarehouse(warehouse);
    }
    return this.updateWarehouse(warehouse);
  },

  updateWarehouse(warehouse) {
    return request({
      url: `/warehouse`,
      method: "put",
      data: warehouse,
    });
  },

  deleteWarehouseById(id, qz_token) {
    return request({
      url: `/warehouse/${id}`,
      method: "delete",
      data: qz_token,
    });
  },

  // 获取所有名称
  selseAllName() {
    return request({
      url: `/warehouse/select`,
      method: "get",
    });
  },
};
